home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / COMM.SWG / 0022_Simple Avatar code.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  3KB  |  120 lines

  1. w{
  2. SEAN PALMER
  3.  
  4. Using the state-driven approach, I came up With this simplistic
  5. Avatar/0 interpreter as an example. Do With it as you wish...
  6.  
  7. by Sean L. Palmer
  8. Public Domain
  9. }
  10.  
  11. Program avtWrite;
  12. { example to do avatar/0 (FSC-0025) interpretation }
  13. { could easily be extended to handle /0+ and /1 codes }
  14.  
  15. Uses
  16.   Crt;
  17.  
  18. { this part of the Program controls the state-driven part of the display
  19.   handler. }
  20.  
  21. Var
  22.   saveAdr : Pointer;  { where state handler is now }
  23.   c       : Char;     { Char accessed by state handler }
  24.   b       : Byte Absolute c;
  25.  
  26. Procedure avtWriteCh(c2 : Char); Inline(
  27.   $8F/$06/>C/            { pop Byte ptr [>c] }
  28.   $FF/$1E/>SAVEADR);     { call dWord ptr [>saveAdr] }
  29.                          { continue where handler l
  30.  
  31.                            call this Procedure from StateHandler to
  32.                            suspend execution Until next time
  33. }
  34.  
  35. Procedure wait; near; Assembler;
  36. Asm                             { wait For next Char }
  37.   pop Word ptr saveAdr          { save where to continue next time }
  38.   retF                          { simulate Exit from calling proc }
  39. end;
  40.  
  41. {
  42.  a stateHandler Procedure should never ever Exit (only by calling 'wait'),
  43.  shouldn't have any local Variables or parameters, and shouldn't call
  44.  'wait' With anything on the stack (like from a subroutine).
  45.  This routine is using the caller's stack, so be careful
  46. }
  47.  
  48. Var
  49.   avc : Char;
  50.   avb : Byte Absolute avc;
  51.  
  52. Procedure stateHandler;
  53. begin
  54.  
  55.   Repeat
  56.  
  57.     Case c of
  58.  
  59.       ^L :
  60.         begin
  61.           ClrScr;
  62.           Textattr := 3;
  63.         end;
  64.  
  65.       ^Y :
  66.         begin
  67.           wait;
  68.           avc := c;
  69.           wait;
  70.           While c <> #0 do
  71.           begin
  72.             dec(c);
  73.             Write(avc);
  74.           end;
  75.         end;
  76.  
  77.       ^V :
  78.         begin
  79.           wait;
  80.           Case c of
  81.  
  82.             ^A :
  83.               begin
  84.                 wait;
  85.                 Textattr := Byte(c);
  86.               end;
  87.             ^B : Textattr := Textattr or $80;
  88.             ^C : if whereY > 1  then GotoXY(whereX, whereY - 1);
  89.             ^D : if whereY < 25 then GotoXY(whereX, whereY + 1);
  90.             ^E : if whereX > 1  then GotoXY(whereX - 1,whereY);
  91.             ^F : if whereX < 80 then GotoXY(whereX + 1,whereY);
  92.             ^G : clreol;
  93.             ^H :
  94.               begin
  95.                 wait;
  96.                 avb := b;
  97.                 wait;
  98.                 GotoXY(b + 1, avb + 1);
  99.               end;
  100.             else
  101.               Write(^V, c);
  102.           end;
  103.         end;
  104.       else
  105.         Write(c);
  106.    end;
  107.    wait;
  108.    Until False;
  109. end;
  110.  
  111. Var
  112.   i : Integer;
  113. Const
  114.   s : String = 'Oh my'^V^D^V^D^V^F^V^A#1'it works'^V^A#4',see?';
  115. begin  {could do something like attach it to Output's InOutFunc...}
  116.   saveAdr := ptr(seg(stateHandler), ofs(stateHandler) + 3); {skip header}
  117.   For i := 1 to length(s) do
  118.     avtWriteCh(s[i]);
  119. end.
  120.